﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace Se.Framework.Common.Data
{
    public sealed class GenericEntityConverterBusinessLayer<TEntity> : IBusinessLayer<IGenericEntity>
        where TEntity : class, IGenericEntity
    {
        private readonly Lazy<IBusinessLayer<TEntity>> businessLayerBase = ObjectRegistry.Current.ResolveLazy<IBusinessLayer<TEntity>>();

        public IQueryable<IGenericEntity> GetItems()
        {
            return businessLayerBase.Value.GetItems();
        }

        public IGenericEntity Find(int id)
        {
            return businessLayerBase.Value.Find(id);
        }

        public void AddItem(IGenericEntity item)
        {
            businessLayerBase.Value.AddItem((TEntity)item);
        }

        public void DeleteItem(IGenericEntity item)
        {
            businessLayerBase.Value.DeleteItem((TEntity)item);
        }

        public void UpdateItem(IGenericEntity item)
        {
            businessLayerBase.Value.UpdateItem((TEntity)item);
        }

        public TDto FindDto<TDto>(int id)
        {
            return businessLayerBase.Value.FindDto<TDto>(id);
        }

        public IEnumerable<TDto> GetDtoItems<TDto>()
        {
            return businessLayerBase.Value.GetDtoItems<TDto>();
        }
    }
}
